Skip to content

feat: allow overriding service name in tracer, meter, and logger config#2883

Merged
omer-topal merged 4 commits intoPermify:masterfrom
mlafreniere-mx:mlafreniere/allow-overriding-service-name-in-telemetry
Apr 21, 2026
Merged

feat: allow overriding service name in tracer, meter, and logger config#2883
omer-topal merged 4 commits intoPermify:masterfrom
mlafreniere-mx:mlafreniere/allow-overriding-service-name-in-telemetry

Conversation

@mlafreniere-mx
Copy link
Copy Markdown
Contributor

@mlafreniere-mx mlafreniere-mx commented Apr 9, 2026

Summary

Closes #2877

Adds a service_name configuration option under tracer, meter, and logger sections, allowing users to override the service name reported by each exporter. Defaults to "permify" for backward compatibility.

Configuration

tracer:
  service_name: new-service-name

meter:
  service_name: new-service-name

logger:
  service_name: new-service-name

CLI flags: --tracer-service-name, --meter-service-name, --log-service-name
Env vars: PERMIFY_TRACER_SERVICE_NAME, PERMIFY_METER_SERVICE_NAME, PERMIFY_LOG_SERVICE_NAME

Test plan

Automated

  • go build ./... — clean build
  • go test ./internal/config/... — 9/9 pass (2 new tests for service name default + override)

Manual testing

Tested locally using grafana/otel-lgtm all-in-one (Grafana + Loki + Tempo + Prometheus + OTel Collector):

docker run -d --name grafana-otel \
  -p 3000:3000 -p 4317:4317 -p 4318:4318 \
  grafana/otel-lgtm:latest

go run ./cmd/permify serve \
  --tracer-enabled=true --tracer-exporter=otlp --tracer-endpoint=localhost:4318 --tracer-insecure=true --tracer-service-name=my-custom-service \
  --meter-enabled=true --meter-exporter=otlp --meter-endpoint=localhost:4318 --meter-insecure=true --meter-interval=5 --meter-service-name=my-custom-service \
  --log-enabled=true --log-exporter=otlp --log-endpoint=localhost:4318 --log-insecure=true --log-level=info --log-service-name=my-custom-service

Then open http://localhost:3000 and verify:

  • Logs (Loki): query {service_name="my-custom-service"} — logs appear with correct service name
  • Metrics (Prometheus): query {job="my-custom-service"} — runtime/host metrics appear
  • Traces (Jaeger / Grafana): search by service my-custom-service — traces appear

Screenshot — Logs in Grafana showing my-custom-service:

logs

Screenshot — Metrics showing my-custom-service:
metrics

Screenshot — Traces in Grafana / Jaeger showing my-custom-service:
image

traces

Summary by CodeRabbit

  • New Features

    • Added customizable service-name for logging, tracing, and metering (default: "permify"); configurable via config files, environment variables, or CLI flags.
  • Documentation

    • Updated configuration guide and example config to document the new service-name options and corresponding environment variables.
  • Tests

    • Added tests to verify service-name defaults and loading from configuration files.
  • Chores

    • Config inspection now displays configured service-name for each telemetry component.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 51e70398-e019-4053-993e-0c40f0c76766

📥 Commits

Reviewing files that changed from the base of the PR and between 02acf05 and 612c172.

📒 Files selected for processing (1)
  • pkg/cmd/config.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/cmd/config.go

📝 Walkthrough

Walkthrough

Adds configurable OpenTelemetry service names for logger, tracer, and meter (default "permify"), exposed via YAML config, CLI flags (--log-service-name, --tracer-service-name, --meter-service-name), and environment variables (PERMIFY_LOG_SERVICE_NAME, PERMIFY_TRACER_SERVICE_NAME, PERMIFY_METER_SERVICE_NAME).

Changes

Cohort / File(s) Summary
Config structs & defaults
internal/config/config.go
Added ServiceName string \mapstructure:"service_name"`toLog, Tracer, and Meterstructs and set default to"permify"inDefaultConfig()`.
Config tests
internal/config/config_test.go
Added tests verifying default service name and YAML override (TestDefaultConfig_ServiceName, TestNewConfigWithFile_ServiceName).
CLI flags & env bindings
pkg/cmd/flags/serve.go, pkg/cmd/serve.go
Added flags --log-service-name, --tracer-service-name, --meter-service-name; bound them to Viper keys and env vars; passed service-name values into telemetry initialization calls.
Telemetry APIs & usage
pkg/telemetry/log.go, pkg/telemetry/tracer.go, pkg/telemetry/meter.go
Extended APIs to accept serviceName string; normalized empty/whitespace to "permify"; used provided value for semconv.ServiceNameKey when building OTLP resources.
Docs & examples
docs/setting-up/configuration.mdx, example.config.yaml
Documented optional service_name for logger, tracer, and meter with default permify; added env var names and example YAML entries; adjusted table formatting.

Sequence Diagram(s)

sequenceDiagram
  participant User as CLI / Config
  participant Viper as Viper (flags/env)
  participant Config as internal/config
  participant Serve as pkg/cmd/serve
  participant Telemetry as pkg/telemetry
  participant OTLP as OTLP Exporter

  User->>Viper: provide flags, env or YAML
  Viper->>Config: populate config (ServiceName fields)
  Config->>Serve: pass cfg with Logger/Tracer/Meter.ServiceName
  Serve->>Telemetry: initialize Logger/Tracer/Meter (pass serviceName)
  Telemetry->>OTLP: create resources with semconv.service.name = serviceName
  OTLP-->>Telemetry: exporter initialized
  Telemetry-->>Serve: initialization complete
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I wore "permify" from hill to glen,
Now names can hop where they please again.
Flags, env, and YAML hum in rhyme—
Tracer, meter, logger keep time.
Hooray for names that bounce in spring!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 70.59% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding configurable service name overrides for tracer, meter, and logger components.
Linked Issues check ✅ Passed The PR fully implements the requirements from issue #2877: configurable service names via config options, CLI flags, and environment variables for tracer, meter, and logger.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing service name configuration for telemetry exporters as specified in issue #2877. No unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 9, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@mlafreniere-mx
Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Apr 9, 2026
@mlafreniere-mx mlafreniere-mx marked this pull request as ready for review April 9, 2026 18:41
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
example.config.yaml (1)

24-27: ⚠️ Potential issue | 🟡 Minor

Missing service_name in logger section.

The logger section is missing the service_name field, but it's been added to both tracer (line 48) and meter (line 56). For consistency and to match the documentation and config struct changes, add service_name: permify here as well.

Proposed fix
 # The logger section sets the logging level for the service.
 logger:
   level: info
   file: "" # Log file path (empty for stdout)
+  service_name: permify
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@example.config.yaml` around lines 24 - 27, The logger configuration is
missing the service_name field; add service_name: permify under the logger
section so it matches the tracer and meter sections and the updated config
struct—specifically update the logger block (logger:, level:, file:) to include
the service_name key with value "permify" to ensure consistency with tracer and
meter entries.
🧹 Nitpick comments (1)
pkg/telemetry/log.go (1)

90-95: Add an empty-value fallback for serviceName.

At Line 94, service.name is set directly from input. If a blank value slips in via config/env/flag, telemetry may emit an empty service name and break service-level dashboards. Consider normalizing to the default before building the resource.

Proposed defensive patch
 import (
 	"context"
 	"errors"
 	"fmt"
 	"log/slog"
 	"os"
 	"runtime"
+	"strings"
@@
 func newResource(serviceName string) *resource.Resource {
+	if strings.TrimSpace(serviceName) == "" {
+		serviceName = internal.Identifier
+	}
 	hostName, _ := os.Hostname()
 	return resource.NewWithAttributes(
 		semconv.SchemaURL,
 		semconv.ServiceNameKey.String(serviceName),
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/telemetry/log.go` around lines 90 - 95, The newResource function sets
semconv.ServiceNameKey directly from the serviceName parameter which can be
blank; add a defensive fallback that normalizes serviceName to a non-empty
default before building the resource (e.g., if serviceName == "" then assign a
constant like defaultServiceName or "unknown_service"), then use that normalized
value when calling resource.NewWithAttributes in newResource.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@example.config.yaml`:
- Around line 24-27: The logger configuration is missing the service_name field;
add service_name: permify under the logger section so it matches the tracer and
meter sections and the updated config struct—specifically update the logger
block (logger:, level:, file:) to include the service_name key with value
"permify" to ensure consistency with tracer and meter entries.

---

Nitpick comments:
In `@pkg/telemetry/log.go`:
- Around line 90-95: The newResource function sets semconv.ServiceNameKey
directly from the serviceName parameter which can be blank; add a defensive
fallback that normalizes serviceName to a non-empty default before building the
resource (e.g., if serviceName == "" then assign a constant like
defaultServiceName or "unknown_service"), then use that normalized value when
calling resource.NewWithAttributes in newResource.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7ba65165-5ffb-465d-af6a-9fe9b736127b

📥 Commits

Reviewing files that changed from the base of the PR and between 50a56d7 and e9022da.

📒 Files selected for processing (9)
  • docs/setting-up/configuration.mdx
  • example.config.yaml
  • internal/config/config.go
  • internal/config/config_test.go
  • pkg/cmd/flags/serve.go
  • pkg/cmd/serve.go
  • pkg/telemetry/log.go
  • pkg/telemetry/meter.go
  • pkg/telemetry/tracer.go

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
pkg/telemetry/log.go (1)

92-94: Normalize serviceName before assigning service.name.

Current logic only checks TrimSpace for emptiness. A value like " my-service " will be emitted with spaces and appear as a distinct service in telemetry backends. Trim once, then apply fallback.

Suggested patch
 func newResource(serviceName string) *resource.Resource {
-	if strings.TrimSpace(serviceName) == "" {
+	serviceName = strings.TrimSpace(serviceName)
+	if serviceName == "" {
 		serviceName = "permify"
 	}
 	hostName, _ := os.Hostname()
 	return resource.NewWithAttributes(
 		semconv.SchemaURL,
 		semconv.ServiceNameKey.String(serviceName),

Also applies to: 98-98

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/telemetry/log.go` around lines 92 - 94, Trim serviceName once and use the
trimmed value for both the emptiness check and the subsequent assignment to
service.name: replace the current strings.TrimSpace check with a single trimmed
:= strings.TrimSpace(serviceName) then if trimmed == "" set serviceName =
"permify" else set serviceName = trimmed; do the same change for the other
occurrence that assigns service.name so no leading/trailing spaces are emitted
to telemetry.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@pkg/telemetry/log.go`:
- Around line 92-94: Trim serviceName once and use the trimmed value for both
the emptiness check and the subsequent assignment to service.name: replace the
current strings.TrimSpace check with a single trimmed :=
strings.TrimSpace(serviceName) then if trimmed == "" set serviceName = "permify"
else set serviceName = trimmed; do the same change for the other occurrence that
assigns service.name so no leading/trailing spaces are emitted to telemetry.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 71720bb0-422c-4009-89ba-cf070c4bec0e

📥 Commits

Reviewing files that changed from the base of the PR and between e9022da and d13622b.

📒 Files selected for processing (3)
  • pkg/telemetry/log.go
  • pkg/telemetry/meter.go
  • pkg/telemetry/tracer.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • pkg/telemetry/tracer.go
  • pkg/telemetry/meter.go

@omer-topal omer-topal self-assigned this Apr 13, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.58%. Comparing base (50a56d7) to head (612c172).
⚠️ Report is 69 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2883      +/-   ##
==========================================
+ Coverage   82.58%   82.58%   +0.01%     
==========================================
  Files          74       74              
  Lines        8297     8300       +3     
==========================================
+ Hits         6851     6854       +3     
  Misses        910      910              
  Partials      536      536              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

@omer-topal omer-topal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add the new logger.service_name, tracer.service_name, and meter.service_name fields to permify config output as well?

Copy link
Copy Markdown
Contributor

@omer-topal omer-topal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

permify config panics on this branch:

go run ./cmd/permify config

flag for "logger.service_name" is nil

pkg/cmd/config.go also needs the new *-service-name flag definitions, not just the output rows.

@mlafreniere-mx
Copy link
Copy Markdown
Contributor Author

go run ./cmd/permify config

permify config panics on this branch:

go run ./cmd/permify config

flag for "logger.service_name" is nil

pkg/cmd/config.go also needs the new *-service-name flag definitions, not just the output rows.

Oups sorry about that

Copy link
Copy Markdown
Contributor

@omer-topal omer-topal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@omer-topal omer-topal merged commit ee8f42a into Permify:master Apr 21, 2026
12 of 13 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

How to configure the OpenTelemetry service name?

2 participants